package com.efun.center.provider;

import com.efun.center.entity.search.EmailServerSearch;
import org.springframework.util.StringUtils;

public class EmailServerProvider {

    public String total(EmailServerSearch search) {
        String sql = "SELECT count(1) FROM t_distribute_email_host WHERE deleted = 0";
        if (!StringUtils.isEmpty(search.getEmailId())) {
            sql += " AND emailId = '" + search.getEmailId() + "'";
        }
        if (!StringUtils.isEmpty(search.getUserName())) {
            sql += " AND userName = '" + search.getUserName() + "'";
        }
        return sql;
    }

    public String query(EmailServerSearch search) {
        String sql = "SELECT * FROM t_distribute_email_host WHERE deleted = 0";
        if (!StringUtils.isEmpty(search.getEmailId())) {
            sql += " AND emailId = '" + search.getEmailId() + "'";
        }
        if (!StringUtils.isEmpty(search.getUserName())) {
            sql += " AND userName = '" + search.getUserName() + "'";
        }
        sql += " ORDER BY modifiedTime DESC LIMIT " + search.getStart() + "," + search.getSize();
        return sql;
    }

}
